// *********************************************************
//      Copyright (c) Kosta Gaitanis
//      All rights reserved
//
//      k.gaitanis@gmail.com
//
// *********************************************************

#ifndef LIGHT_H
#define LIGHT_H

#include <QMetaType>
#include <QtOpenGL/QtOpenGL>

/**
 * @brief The Light class implements a light in openGL.
 * @author Kosta Gaitanis
 */
class Light
{
public:
    /**
     * @brief Constructor
     * @param name the name of this light.
     */
    Light(const QString& name = QString());

    /**
     * Destructor
     */
    ~Light();

    /**
     * @brief initializes the light parameters.
     */
    void initializeGL();

    /**
     * @brief paints this light.
     */
    void paint();

    /**
     * @param ambient The ambient color of this light.
     */
    void setAmbient(const QColor& ambient);

    /**
     * @param ambient The diffuse color of this light.
     */
    void setDiffuse(const QColor& diffuse);

    /**
     * @param ambient The specular color of this light.
     */
    void setSpecular(const QColor& specular);

    /**
     * @param ambient The position of this light.
     */
    void setPosition(double x, double y, double z, double w = 1.0);

    /**
     * @return The ambient color of this light.
     */
    QColor getAmbient() const;

    /**
     * @return The diffuse color of this light.
     */
    QColor getDiffuse() const;

    /**
     * @return The specular color of this light.
     */
    QColor getSpecular() const;

    /**
     * @return The position of this light.
     */
    const GLfloat *getPosition() const;

    /**
     * @return The name of this light.
     */
    const QString& getName() const;

    /**
     * @brief Turns this light on/off
     * @param on true to turn on
     */
    void setOn(bool on = true);

    /**
     * @return True if this light is on.
     */
    bool isOn() const;

private:
    Q_DISABLE_COPY(Light)

    GLenum m_lightId;               /// > The light id.
    GLfloat m_ambient[4];           /// > The ambien color
    GLfloat m_diffuse[4];           /// > The diffuse color
    GLfloat m_specular[4];          /// > The specular color
    GLfloat m_position[4];          /// > The position
    QString m_name;                 /// > The name of this light.
    bool m_isOn;                    /// > True if the light is on.
};

Q_DECLARE_METATYPE(Light*)

#endif // LIGHT_H
